$(document).ready(function() {
	// $('.order_lst_tab li').click(function(event) {
	// 	var status = $(this).index()+1;
	// 	 $(this).eq($(this).index()).addClass("act").siblings().removeClass('act');
	// 	window.location.href=url + '?status=' +status
	// });

	// $('.order_lst_tab li').each(function(index, el) {
	// 	var status = decodeURIComponent((new RegExp('[?|&]status=' + '([^&;]+?)(&|#|;|$)', "ig").exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
	// 	$('.order_lst_tab li').eq(status-1).addClass('act').siblings().removeClass('act');
	// 	if (!status) {
	// 		$('.order_lst_tab li').eq(0).addClass('act').siblings().removeClass('act');
	// 	}
	// });



		// loading  加载
		var stop = true;
		page = 2;
		var status = decodeURIComponent((new RegExp('[?|&]status=' + '([^&;]+?)(&|#|;|$)', "ig").exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
  function show(){}
  show()
		$(window).scroll(function() {
			var totalheight = parseFloat($(window).height()) + parseFloat($(window).scrollTop());

			if ($(document).height() <= totalheight) {
				if (stop == true) {
					stop = false;

					  $.ajax({
							url: url,
							type: 'get',
							data: {
								page: page,
								status:status
							},
							success: function(data) {
								
								var html = '';
								var data = JSON.parse(data)
								console.log(data)
								if (data.code == 1) {
									function formatDate(now) { 
										var year=now.getYear(); 
										var month=now.getMonth()+1; 
										var date=now.getDate(); 
										var hour=now.getHours(); 
										var minute=now.getMinutes(); 
										var second=now.getSeconds(); 
										return "20"+year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second; 
										} 
									
									for (var i = 0; i < data.data.order_lst.length; i++) {
										html +='<li>'+
													'<div class="order_lst_time">订单日期：'+new Date(data.data.order_lst[i].create_date * 1000).toLocaleString().replace(/\-(\d)\b/g, "-0$1")+'';
													if (data.data.order_lst[i].order_status == 2) {
														html +='<span class="order_lst_dai">待付款</span>'
													}else if (data.data.order_lst[i].order_status == 3) {
														html +='<span class="order_lst_dai">待发货</span>'
													}else if (data.data.order_lst[i].order_status == 4) {
														html +='<span class="order_lst_dai">待收货</span>'
													}else if (data.data.order_lst[i].order_status == 5) {
														html +='<span class="order_lst_dai">已收货</span>'
													}else if (data.data.order_lst[i].order_status == 6) {
														html +='<span class="order_lst_dai">订单已取消</span>'
													}
													
											html +='</div>'+
													'<a href='+href+'?order_id='+data.data.order_lst[i].order_id+'>'+
														'<div class="order_proimg"><img src="'+data.data.order_lst[i].product_thumb_img+'" alt=""></div>'+
														'<div class="order_des">'+
														'<div class="order_protitle"><div class="order_prot">';
														
														if(data.data.order_lst[i].sorce == 2){
															
															html +='<p class="choujiang">抽奖</p>';
														}
														
														html += data.data.order_lst[i].product_title+'</div><p class="order_protitle_money"><img src="'+img_url+'/images/4_19.png" alt="">'+data.data.order_lst[i].product_need_npoint+'</p></div>'+
															'<div class="order_color"><span>'+data.data.order_lst[i].product_attr_name+'</span><p class="order_number">x'+data.data.order_lst[i].number+'</p></div>'+
														'</div>'+
														'<div class="order_lst_zongji">共<span>'+data.data.order_lst[i].number+'</span>件商品 总计：<img src="'+img_url+'/images/4_19.png" alt="">'+data.data.order_lst[i].total_price+'</div>'+
													'</a>'
													if (data.data.order_lst[i].order_status == 4) {
														html +='<div class="order_lst_btn">'+
																'<div class="order_lst_b confirm_goods" data-c="'+data.data.order_lst[i].order_id+'">确认收货</div>'+
															'</div>'
													}
											html +='</li>'
									};
								}else{
									$(".Loading").html("数据加载失败");
								}
							
								
								$('#order_list').append(html)
								stop = true;
								page++;
								
								if (data.data.order_lst.length < 10) {
									$(".Loading").html("全部加载完！");
									stop = false;
								} else {
									$(".Loading").html("Loading...");
								}
							},
							error:function(xhr, textStatus){
								if(xhr.status == 401){
									 window.location.href = "/Npoint_store/Login";
								}else{
									alert('系统错误')
								}

							}
						})
				  
				}
			}
		});


		//确认收货
		$(document).on('click','.confirm_goods',function(event) {
			var order_id = $(this).attr('data-c')
			$.ajax({
				url: confirm_goods_url,
				type: 'GET',
				data: {
					order_id: order_id
				},
				success: function(data) {
					alert(JSON.parse(data).desc)
					window.location.reload(); 
				}
			})
		});


		


		
});

